package com.tpv.tv.lib.pdf;

import static android.content.Context.WINDOW_SERVICE;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.util.DisplayMetrics;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

public class PdfCommUtil {
    public static int getAccurateScreenOrientation(Context context) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        if (displayMetrics.heightPixels > displayMetrics.widthPixels) {
            return Configuration.ORIENTATION_PORTRAIT;
        } else {
            return Configuration.ORIENTATION_LANDSCAPE;
        }
    }

    public static boolean isLandscape(Context context) {
        return context.getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE;
//        WindowManager windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);
//        int rotation = windowManager.getDefaultDisplay().getRotation();
//        boolean isLandscape; // 是横屏
//        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
//            isLandscape = rotation != Surface.ROTATION_0;
//        } else {
//            isLandscape = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270;
//        }
//        return isLandscape;
    }

    public static void closeKeyboard(Context context, View view) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null && view != null) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
}
